//import com.qian.api.ddj.model.CountQueryModel;
//import com.qian.api.ddj.model.Order;
//import com.qian.api.ddj.service.ICashService;
//import com.qian.api.ddj.service.IHolidayService;
//import com.qian.service.ddj.dao.BusinessRepository;
//import com.qian.service.ddj.dao.ChannelRepository;
//import com.qian.service.ddj.dao.OrderRepository;
//import com.qian.service.ddj.dao.UserRepository;
//import com.qian.service.ddj.entity.DdjBusiness;
//import com.qian.service.ddj.entity.DdjChannel;
//import com.qian.service.ddj.entity.DdjOrder;
//import com.qian.service.ddj.entity.DdjUser;
//import com.yaowk.api.common.BaseModel;
//import com.yaowk.api.common.IBaseService;
//import com.yaowk.api.common.PageReq;
//import com.yaowk.api.common.PageResp;
//import com.yaowk.service.common.BaseRepository;
//import com.yaowk.service.common.BaseServiceImpl;
//import org.junit.Test;
//import org.junit.runner.RunWith;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.domain.Page;
//import org.springframework.data.domain.PageRequest;
//import org.springframework.data.domain.Sort;
//import org.springframework.data.jpa.domain.Specification;
//import org.springframework.stereotype.Service;
//import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
//import org.springframework.test.context.web.WebAppConfiguration;
//import org.springframework.util.ObjectUtils;
//import org.springframework.util.StringUtils;
//
//import javax.persistence.EntityManager;
//import javax.persistence.PersistenceContext;
//import javax.persistence.criteria.*;
//import javax.transaction.Transactional;
//import java.math.BigDecimal;
//import java.util.*;
//import java.util.Date;
//
//@RunWith(SpringJUnit4ClassRunner.class)
//@WebAppConfiguration
//public class CounQuery extends BaseServiceImpl {
//    @Autowired
//    private OrderRepository dao;
//    @Autowired
//    private UserRepository userDao;
//    @PersistenceContext
//    private EntityManager em;
//    @Autowired
//    private ICashService cashService;
//    @Autowired
//    private BusinessRepository businessDao;
//    @Autowired
//    private IHolidayService holidayService;
//    @Autowired
//    private ChannelRepository channelDao;
//
//    public PageResp<Order> countQuery(PageReq pageReq, final CountQueryModel model) {
//        PageRequest pageRequest = new PageRequest(pageReq.getPageNumber() - 1, pageReq.getPageSize(), new Sort(Sort.Direction.DESC, "createTime"));
//        Page<DdjOrder> page = dao.findAll(new Specification<DdjOrder>() {
//            @Override
//            public Predicate toPredicate(Root<DdjOrder> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
//                Path<Date> timePath = root.get("createTime");
//                Path<Byte> statusPath = root.get("payType");
//                Root<DdjChannel> ddjChannelRoot = criteriaQuery.from(DdjChannel.class);
//
//                Predicate condition = criteriaBuilder.isNotNull(root.<Integer>get("id"));
//                // 用户比较
//                if (isNotEmpty(model.getUserId()))
//                    condition = criteriaBuilder.and(condition, criteriaBuilder.equal(root.<Integer>get("userId"), model.getUserId()));
//                // 通道比较
//                if (isNotEmpty(model.getChannelId()))
//                    condition = criteriaBuilder.and(condition, criteriaBuilder.equal(ddjChannelRoot.<Integer>get("id"), model.getChannelId()));
//                // 日期比较
//                if (isNotEmpty(model.getIndexDate()) && isNotEmpty(model.getEndDate()))
//                    condition = criteriaBuilder.and(condition, criteriaBuilder.between(timePath, model.getIndexDate(), model.getEndDate()));
//                else if (isNotEmpty(model.getIndexDate()))
//                    condition = criteriaBuilder.and(condition, criteriaBuilder.greaterThanOrEqualTo(timePath, model.getIndexDate()));
//                else if (isNotEmpty(model.getEndDate()))
//                    condition = criteriaBuilder.and(condition, criteriaBuilder.lessThanOrEqualTo(timePath, model.getEndDate()));
//                // 支付类型比较
//                if (isNotEmpty(model.getPayType()))
//                    condition = criteriaBuilder.and(condition, criteriaBuilder.equal(root.<Byte>get("payType"), model.getPayType()));
//                return condition;
//            }
//        }, pageRequest);
//
//        PageResp<Order> pageResp = page2pageResp(page);
//        for (Order order : pageResp.getList()) {
//            DdjUser user = userDao.findOne(order.getUserId());
//            order.setUsername(user.getUsername());
//            if (isNotEmpty(order.getBusinessId())) {
//                DdjBusiness ddjBusiness = businessDao.findOne(order.getBusinessId());
//                order.setBusinessName(ddjBusiness.getName());
//            }
//        }
//        return pageResp;
//    }
//
//    @Test
//    public void test() {
//        PageReq pageReq = new PageReq();
//        pageReq.setPageNumber(1);
//        pageReq.setPageSize(20);
//        CountQueryModel countQueryModel = new CountQueryModel();
//        countQueryModel.setUserId(2);
//
//
//
//    }
//
//    @Override
//    protected BaseRepository getDao() {
//        return null;
//    }
//
//    @Override
//    protected Object model2Entity(BaseModel model) {
//        return null;
//    }
//
//    @Override
//    protected BaseModel entity2model(Object entity) {
//        return null;
//    }
//
//    public Object orderTocountQuery(DdjOrder ddjOrder) {
//        CountQueryModel model = new CountQueryModel();
//        if (isNotEmpty(ddjOrder.getUserId())){
//            model.setUserId(ddjOrder.getUserId());
//        }
//        if (isNotEmpty(ddjOrder.getPayType())){
//            model.setPayType(ddjOrder.getPayType());
//        }
//        if (isNotEmpty(ddjOrder.getAmount().doubleValue())){
//            model.setAmount(ddjOrder.getAmount().doubleValue());
//        }
//        if (isNotEmpty(ddjOrder.getCreateTime())){
//            model.setCreatDate(ddjOrder.getCreateTime());
//        }
//        return model;
//    }
//}
//
